﻿set(TARGET_NAME OpenVisaApplication)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

include_directories("../")

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Network REQUIRED)
find_package(OpenVisa CONFIG REQUIRED)
find_package(QCustomUi CONFIG REQUIRED)
find_package(Xlnt CONFIG REQUIRED)
find_package(pegtl CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)

add_compile_definitions(OPENVISA_APPLICATION_VERSION="${PROJECT_VERSION}")

file(GLOB SOURCES "*.cpp")
file(GLOB HEADERS "*.h")
file(GLOB UI "*.ui")
file(GLOB ABOUT "About/*.h" "About/*.cpp" "About/*.ui")
file(GLOB TEST_VIEW "TestView/*.h" "TestView/*.cpp" "TestView/*.ui")
file(GLOB NETWORK_DEVICE "NetworkDevice/*.h" "NetworkDevice/*.cpp" "NetworkDevice/*.ui")
file(GLOB RESOURCES "*.qrc" "*.rc")
file(GLOB EXCEL "Excel/*.h" "Excel/*.cpp")
file(GLOB ATTRIBUTE "Attribute/*.h" "Attribute/*.cpp")
file(GLOB UPDATE "Update/*.h" "Update/*.cpp")
file(GLOB IO_TRACE "IOTrace/*.h" "IOTrace/*.cpp")

source_group("Headers" FILES ${HEADERS})
source_group("Sources" FILES ${SOURCES})
source_group("UI" FILES ${UI})
source_group("About" FILES ${ABOUT})
source_group("Resources" FILES ${RESOURCES})
source_group("TestView" FILES ${TEST_VIEW})
source_group("NetworkDevice" FILES ${NETWORK_DEVICE})
source_group("Excel" FILES ${EXCEL})
source_group("Attribute" FILES ${ATTRIBUTE})
source_group("Update" FILES ${UPDATE})
source_group("IOTrace" FILES ${IO_TRACE})

set(ICON_PATH "${CMAKE_CURRENT_LIST_DIR}\\Resources\\ICON.ico")

if(MSVC)
    set(VERSIONINFO_RC ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}.rc)
    configure_file("${PROJECT_SOURCE_DIR}/cmake/OpenVisaApplication.rc.in" "${VERSIONINFO_RC}")
    list(APPEND RESOURCES ${VERSIONINFO_RC})
endif(MSVC)

add_executable(${TARGET_NAME} WIN32 ${SOURCES} ${HEADERS} ${UI} ${ABOUT} ${RESOURCES} ${TEST_VIEW} ${NETWORK_DEVICE} ${EXCEL} ${ATTRIBUTE} ${UPDATE} ${IO_TRACE})

target_link_libraries(${TARGET_NAME} PUBLIC AppCore IOTraceService PRIVATE Qt::Widgets Qt::Network QCustomUi OpenVisa xlnt::xlnt taocpp::pegtl nlohmann_json::nlohmann_json)
install(IMPORTED_RUNTIME_ARTIFACTS OpenVisa QCustomUi libusb DESTINATION ${INSTALL_BINDIR}/${CMAKE_BUILD_TYPE})
install(TARGETS ${TARGET_NAME} RUNTIME DESTINATION ${INSTALL_BINDIR}/${CMAKE_BUILD_TYPE})
